package com.gt.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gt.common.annotation.Log;
import com.gt.common.core.controller.BaseController;
import com.gt.common.core.domain.AjaxResult;
import com.gt.common.enums.BusinessType;
import com.gt.admin.domain.Template;
import com.gt.admin.domain.apiVO.TemplateVVO;
import com.gt.admin.service.ITemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 结构化模板controller
 */
@Api(tags = "sc-结构化模板")
@RestController
@RequestMapping("/template")
public class TemplateController extends BaseController {
    @Autowired
    private ITemplateService templateService;

    /**
     * 查询结构化模板
     */
    @ApiOperation("查询结构化模板")
    @GetMapping
    public AjaxResult list(Template template){
        LambdaQueryWrapper<Template> queryWrapper = new LambdaQueryWrapper<>(template);
        List<Template> list = templateService.list(queryWrapper);
        return AjaxResult.success(list);
    }

    /**
     * 按superid查询版本
     */
    @ApiOperation("按superid查询版本")
    @GetMapping("/version/{superid}")
    public AjaxResult listVersion(@PathVariable("superid") Long superid){
        return AjaxResult.success(templateService.selectVersion(superid));
    }

    /**
     * 按superid查询结构化模板
     */
    @ApiOperation("按superid查询结构化模板")
    @GetMapping("/{superid}")
    public AjaxResult list(@PathVariable("superid") Long superid){
        return AjaxResult.success(templateService.selectBySuperId(superid));
    }

    /**
     * 新增或修改结构化模板，更新生效版本
     */
    @ApiOperation("新增或修改结构化模板")
    @Log(title = "结构化模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult update(@RequestBody TemplateVVO templateVVO){
        return toAjax(templateService.update(templateVVO));
    }

    /**
     * 删除结构化模板
     */
    @ApiOperation("删除结构化模板")
    @Log(title = "结构化模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id")Long id){
        return toAjax(templateService.delete(id));
    }
}
